package org.luxor.commons.rabbitmq.service.topic;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 2 号主题关注者
 *
 * @author Mr.Yan  @date 2019/10/16$
 */
@Component
public class InfoLogWatcher {

    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(value = "exchange.topic",type = "topic"),
            key = "info.#",
            value = @Queue("queue.infoLogWatcher")
    ))
    public void onMessage(String message, Channel channel,  @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag)  throws IOException {
        System.out.println("[infoLog] 关注者接收到：" + message);
        // 确认消息
        channel.basicAck(deliveryTag, false);
    }

}
